/*
 * $Id: CategoryProgrammeAttributeDao.java 1700 2011-08-29 11:42:38Z abie $
 * 
 * Copyright (c) 2001-2008 Accentrix Company Limited. All Rights Reserved.
 */
package com.lightsaber.trade.cloth.dao.category;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Component;

import com.lightsaber.trade.core.dao.BaseDao;
import com.lightsaber.trade.cloth.entity.category.CategoryLeaf;
import com.lightsaber.trade.cloth.entity.category.CategoryProgrammeAttribute;
import com.lightsaber.trade.cloth.service.param.ParamService;

@Component
public class CategoryProgrammeAttributeDao extends BaseDao<CategoryProgrammeAttribute, String> {

    public List<CategoryProgrammeAttribute> findByCategoryNodeId(final String categoryNodeId) {
        return eq("categoryLeaf.id", categoryNodeId).list();
    }

    public void deleteByCategoryNodeId(final String categoryNodeId) {
        Query q = getSession().createQuery(
                "delete from CategoryProgrammeAttribute c where c.categoryLeaf.id=:categoryNodeId");
        q.setParameter("categoryNodeId", categoryNodeId);
        q.executeUpdate();
    }

    public CategoryProgrammeAttribute findByFundingMode(final CategoryLeaf leaf) {
        eq("categoryLeaf.id", leaf.getId());
        eq("programmeAttribute", ParamService.FUNDING_MODE);
        return unique();
    }

}
